<%@page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %>
<%@include file="/common/common.jsp"%>
<h:css href="/css/style1/style-custom.css"/>
<%@include file="/common/skins/skin0/component.jsp" %>
<html>
<!-- 
  - Author(s): pengweiling
  - Date: 2012-08-26 08:50:18
  - Description:
-->
<head>
  <title>房控图</title> 
  <style>
     .useroom{
       background-color:blue;
     }
     
     .origroom{
       background-color:green;
     }
     
     .badroom{
       background-color:red;
     }
     
     .badroom{
       background-color:grey;
     }
          
  </style>
</head>
<body>
  
  
    <e:datasource name="criteria" type="entity" path="com.primeton.das.criteria.criteraiType" />
    <e:datasource name="page" type="entity" path="com.eos.foundation.PageCond" />
    <queryform id= "b187c7db-5f71-47e3-89fa-fdfe7c69d699">
      <h:form  name="query_form" action="com.hms.report.roomctrlview.flow" checkType="blur" target="_self" method="post" onsubmit="return checkCond(this);">
        <input type="hidden" name="_eosFlowAction" value="pageQuery"/>

          <table align="center" border="0" width="100%" class="form_table">
            <tr>
              <td class="form_label">
                小区
              </td>
              <td colspan="1">
                <h:text property="criteria/_expr[1]/careaname"/>
                <h:hidden property="criteria/_expr[1]/_op" value="like"/>
                <h:hidden property="criteria/_expr[1]/_likeRule" value="all"/>
              </td>
              <td class="form_label">
                房号
              </td>
              <td colspan="1">
                <h:text property="criteria/_expr[2]/croomno"/>
                <h:hidden property="criteria/_expr[2]/_op" value="like"/>
                <h:hidden property="criteria/_expr[2]/_likeRule" value="all"/>
              </td>
              
              <td class="form_label">
                房型
              </td>
              <td colspan="1">
                <d:select dictTypeId="HMS_Room_Type"  nullLabel="请选择" property="criteria/_expr[3]/croomtype" style="width:128px;"/>
                <h:hidden property="criteria/_expr[3]/_op" value="="/>
              </td>           
            </tr>
            <tr>
              <td class="form_label">
                开始日期
              </td>
              <td colspan="1">
                <w:date property="startDate"/>
              </td>
              <td class="form_label">
                结束日期
              </td>
              <td colspan="1">
                <w:date property="endDate"/>
              </td>
              
              <td class="form_label">
              </td>
              <td colspan="1">
              </td>           
            </tr>
                        
            <tr class="form_bottom">
              <td colspan="6" class="form_bottom">
                <input type="hidden" name="criteria/_entity" value="com.hms.OrderMgr.order.WeRoomsV">
                每页显示
                <h:text size="2" property="page/length" value="10" validateAttr="minValue=1;maxValue=100;type=integer;isNull=true" />
                <input type="hidden" name="page/begin" value="0">
                <input type="hidden" name="page/isCount" value="true">
                <input type="submit" value="查询" class="button">
              </td>
            </tr>
          </table>
    
      </h:form>
    </queryform>
    <br/>
    <viewlist id= "c982df22-9e5b-4902-8ad9-b6934e059711">
      <h:form name="page_form" action="com.hms.report.roomctrlview.flow" method="post">
        <input type="hidden" name="_eosFlowAction" value="query" >
        <h:hiddendata property="criteria" />
        <input type="hidden" name="startDate" value='<b:write property="startDate"/>'>
        <input type="hidden" name="endDate" value='<b:write property="endDate"/>'>  
        <h:hidden property="page/begin"/>
        <h:hidden property="page/length"/>
        <h:hidden property="page/count"/>
        <h:hidden property="page/isCount"/>

          <table align="center" border="0" width="100%" class="EOS_table">
            <tr>
              <th align="center">
                区域
              </th>
              <th>
                小区
              </th>
              <th>
                栋号
              </th> 
              <th>
                楼层
              </th>                             
              <th>
                房号
              </th>
              <th>
                房间类型
              </th>
              <th>
                房间样式
              </th>
              <%
                
                //循环日期，将日期范围内的数据显示
                java.util.Date startDate = null;
                java.util.Date endDate = null;
                int ic = 0;
                String blankDate = "";
                
                if (request.getAttribute("startDate") != null){
                  startDate = (java.util.Date)request.getAttribute("startDate");
                }
                
                if (request.getAttribute("endDate") != null){
                  endDate = (java.util.Date)request.getAttribute("endDate");
                }
                
                String header = "";
                if (startDate != null && endDate != null){
                  java.util.Date tmp =new java.util.Date();
                  tmp.setTime(startDate.getTime());
                  while (tmp.getTime() <= endDate.getTime()){
                    header += "<th>" + 
                              com.eos.foundation.common.utils.DateUtil.format(tmp, "yyyy-MM-dd") + 
                              "</th>";
                              
                    tmp.setTime(tmp.getTime() + 1 * 24 * 60 * 60 * 1000);
                    ic++;
                  }
                }
                for(int i = 0; i < ic; i++){
                  blankDate += "<td></td>";
                }
                ic = ic + 7;
               %>
               
               <%=header %>
            </tr>
            
            <%
               
               String blank = "", result = "";
               for(int i = 0; i < ic; i++){
                 blank += "<td></td>";
               }
               
               commonj.sdo.DataObject[] rooms = null;
               if (request.getAttribute("rooms") != null){
                  rooms = (commonj.sdo.DataObject[])request.getAttribute("rooms");
               }
               
               if (rooms != null && rooms.length > 0){
                  String tk = "";
                  for(int i = 0; i < rooms.length; i++){
                    tk = "";
                    tk += "<td>" + (rooms[i].getString("carea") == null ? "":rooms[i].getString("carea")) + "</td>";
                    tk += "<td>" + (rooms[i].getString("careaname") == null ? "":rooms[i].getString("careaname")) + "</td>";
                    tk += "<td>" + (rooms[i].getString("cbuilding") == null ? "":rooms[i].getString("cbuilding")) + "</td>";
                    tk += "<td>" + (rooms[i].getString("cfloor") == null ? "":rooms[i].getString("cfloor")) + "</td>";
                    tk += "<td>" + (rooms[i].getString("croomno") == null ? "":rooms[i].getString("croomno")) + "</td>";
                    tk += "<td>" + (rooms[i].getString("croomtype") == null ? "":rooms[i].getString("croomtype")) + "</td>";
                    tk += "<td>" + (rooms[i].getString("croomstyle") == null ? "":rooms[i].getString("croomstyle")) + "</td>";
                    
                    
                    //找到客单
                    String dateStr = "";
                    if (startDate != null && endDate != null){
                      java.util.Date tmp = new java.util.Date(startDate.getTime());
                      while (tmp.getTime() <= endDate.getTime()){
                         commonj.sdo.DataObject[] orders = null;
                         if (rooms[i].get("orders") != null){
                           orders = (commonj.sdo.DataObject[])rooms[i].get("orders");
                         }
                         
                         if (orders != null && orders.length > 0){
                           for(int j = 0; j < orders.length; j++){
                             java.util.Date arrDate = orders[j].getDate("darrdate");
                             java.util.Date depDate = orders[j].getDate("ddepdate");
                             java.util.Date arrOrigDate = orders[j].getDate("arrorigdate");
                             if (arrDate != null){
                                arrOrigDate = arrDate;
                             }
                             java.util.Date depOrigDate = orders[j].getDate("deporigdate");  
                             String status = orders[j].getString("cstatus");
                             if (status.equals("R")){//预订
                                if (tmp.getTime() >= arrOrigDate.getTime() && tmp.getTime() <= depOrigDate.getTime()){
                                  dateStr += "<td class='origroom'>" + (orders[j].getString("cgresno")) + "</td>";
                                  
                                }else{
                                  continue;
                                }
                             }else if (status.equalsIgnoreCase("I")){
                                if (tmp.getTime() >= arrOrigDate.getTime() && tmp.getTime() <= depOrigDate.getTime()){
                                  dateStr += "<td class='useroom'>" + (orders[j].getString("cgresno")) + "</td>";
                                }else{
                                  continue;
                                }                             
                                
                             }else{
                                dateStr += "<td></td>";
                             }
                           }
                         }
                         tmp.setTime(tmp.getTime() + 1 * 24 * 60 * 60 * 1000);
                      }
                    }
                    tk += (dateStr.equals("") ? blankDate : dateStr);
                                    
                    if (i % 2 != 0){
                      tk = "<tr>" + tk + "</tr>";
                    }else{
                      tk = "<tr class='EOS_table_row'>" + tk + "</tr>";
                    }
                    
                    result += tk;
                  }
               }
               
               if ("".equals(result)){
                  result = blank;
               }
               
             %>
             
             <%=result %>

            <tr>
              <td colspan="<%=ic %>" class="command_sort_area">
                <div style="float:right">
                  <l:equal property="page/isCount" targetValue="true">
                    共
                    <b:write property="page/count"/>
                    条记录 第
                    <b:write property="page/currentPage"/>
                    页/
                    <b:write property="page/totalPage"/>
                    页
                  </l:equal>
                  <l:equal property="page/isCount" targetValue="false">
                    第
                    <b:write property="page/currentPage"/>
                    页
                  </l:equal>
                  <input type="button" onclick="firstPage('page', 'pageQuery', null, null, 'page_form');" value="首页"  <l:equal property="page/isFirst" targetValue="true">disabled</l:equal> >
                  <input type="button" onclick="prevPage('page', 'pageQuery', null, null, 'page_form');" value="上页" <l:equal property="page/isFirst" targetValue="true">disabled</l:equal> >
                  <input type="button" onclick="nextPage('page', 'pageQuery', null, null, 'page_form');" value="下页" <l:equal property="page/isLast" targetValue="true">disabled</l:equal> >
                  <l:equal property="page/isCount" targetValue="true">
                    <input type="button" onclick="lastPage('page', 'pageQuery', null, null, 'page_form');" value="尾页" <l:equal property="page/isLast" targetValue="true">disabled</l:equal> >
                  </l:equal>
                </div>
              </td>
            </tr>
          </table>

      </h:form>
    </viewlist>
    <script>
       function checkCond(frm){
         var x = $name("startDate").value, y = $name("endDate").value;
         if (!x || !y){
            alert("必须指定日期范围条件");
            return false;
         }
         
         x = stringToDate(x, 'yyyy-MM-dd');
         y = stringToDate(y, 'yyyy-MM-dd');
         if (y.getTime() < x.getTime()){
           alert("结束日期必须大于开始日期");
           return false;
         }
         
         if ((y - x) > 20 * 24 * 60 * 60 * 1000){
           alert("最多允许查询20天内的房控图");
           return false;
         }
         
         return checkForm(frm);
       }
    </script>
      
</body>

</html>
